<!--
 * @Date: 2019-12-25 09:46:04
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2020-04-27 19:13:54
 * @describe: -调取记录-
 -->
<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-house__housephonelog}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          时间：
          <el-select
            v-model="dataForm.date"
            @change="dateSelectChange"
            class="FormSelect"
            clearable
          >
            <el-option label="自定义" value="6"></el-option>
            <el-option label="当天" value="1"></el-option>
            <el-option label="本周" value="2"></el-option>
            <el-option label="本月" value="3"></el-option>
            <el-option label="本季度" value="4"></el-option>
            <el-option label="今年" value="5"></el-option>
          </el-select>&nbsp;
          <el-date-picker
            v-model="dataForm.createDates"
            type="date"
            placeholder="开始时间"
            value-format="yyyy-MM-dd"
            style="width:136px"
            :disabled="dataForm.date!='6'"
          ></el-date-picker>
          {{' -'}}
          <el-date-picker
            v-model="dataForm.createDatee"
            type="date"
            placeholder="结束时间"
            value-format="yyyy-MM-dd"
            style="width:136px"
            :disabled="dataForm.date!='6'"
          ></el-date-picker>
        </el-form-item>

        <el-form-item>
          部门：
          <el-cascader
            class="FormSelect"
            v-model="deptSelectVal"
            :options="this.$store.state.DeptList"
            :show-all-levels="false"
            @change="deptIdChange"
            :props="deptProps"
            ref="myCascader"
            clearable
          ></el-cascader>-
          <el-select v-model="dataForm.userId" placeholder="人员" class="FormSelect" clearable>
            <el-option
              v-for="item in maintainList"
              :key="item.id"
              :label="item.realName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="Reset">重置</el-button>
        </el-form-item>
        <el-form-item>
          <el-input v-model="dataForm.id" placeholder="搜索房源" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <!-- <el-form-item>
                    <el-button type="info" @click="exportHandle()">{{ $t('export') }}</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button
                        v-if="$hasPermission('house:housephonelog:save')"
                        type="primary"
                        @click="addOrUpdateHandle()"
                    >{{ $t('add') }}</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button
                        v-if="$hasPermission('house:housephonelog:delete')"
                        type="danger"
                        @click="deleteHandle()"
                    >{{ $t('deleteBatch') }}</el-button>
        </el-form-item>-->
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        :height="autoTabHeight"
        border
        @selection-change="dataListSelectionChangeHandle"
        style="width: 100%;"
      >
        <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <!-- <el-table-column prop="id" label="主键" header-align="center" align="center"></el-table-column> -->
        <el-table-column prop="houseId" label="房源编号" header-align="center" align="center">
          <template
            slot-scope="scope"
          >{{"FY - "+scope.row.houseId.substring(scope.row.houseId.length-6)}}</template>
        </el-table-column>
        <el-table-column prop="deptName" label="查看人部门" header-align="center" align="center"></el-table-column>
        <el-table-column prop="userName" label="查看人" header-align="center" align="center"></el-table-column>
        <el-table-column prop="createDate" label="查看时间" header-align="center" align="center"></el-table-column>
        <!-- <el-table-column
                    :label="$t('handle')"
                    fixed="right"
                    header-align="center"
                    align="center"
                    width="150"
                >
                    <template slot-scope="scope">
                        <el-button
                            v-if="$hasPermission('house:housephonelog:update')"
                            type="text"
                            size="small"
                            @click="addOrUpdateHandle(scope.row.id)"
                        >{{ $t('update') }}</el-button>
                        <el-button
                            v-if="$hasPermission('house:housephonelog:delete')"
                            type="text"
                            size="small"
                            @click="deleteHandle(scope.row.id)"
                        >{{ $t('delete') }}</el-button>
                    </template>
        </el-table-column>-->
      </el-table>
      <div class="paginationBox">
        <el-pagination
          :current-page="page"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="limit"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="pageSizeChangeHandle"
          @current-change="pageCurrentChangeHandle"
        ></el-pagination>
      </div>
      <!-- 弹窗, 新增 / 修改 -->
      <!-- <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update> -->
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
// import AddOrUpdate from './housephonelog-add-or-update'
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/house/houseinfo/housephonelog",
        getDataListIsPage: true,
        exportURL: "/house/housephonelog/export",
        deleteURL: "/house/housephonelog",
        deleteIsBatch: true
      },
      dataForm: {
        id: "",
        date: "6",
        createDates: "",
        createDatee: "",
        deptId: "", //部门
        userId: "",
        search: "",
        houseId: this.HousingID
      },
      deptSelectVal: "",
      deptProps: {
        value: "id",
        label: "name",
        checkStrictly: true
      },
      maintainList: this.$store.state.maintainList
    };
  },
  props: ["HousingID"],
  components: {
    // AddOrUpdate
  },
  created() {
    this.autoWidth();
  },
  mounted() {
    let _this = this;
    window.onresize = function() {
      _this.autoWidth();
    };
  },
  methods: {
    autoWidth() {
      let w = document.documentElement.clientWidth || document.body.clientWidth;
      let h =
        document.documentElement.clientHeight || document.body.clientHeight;
      if (w < 1740 && w > 1610) {
        this.autoTabHeight = h - 160;
      } else if (w < 1610) {
        this.autoTabHeight = h - 230;
      } else {
        this.autoTabHeight = h - 130;
      }
    },
    // 日期方式切换
    dateSelectChange(val) {
      if (val != "6") {
        this.dataForm.createDates = "";
        this.dataForm.createDatee = "";
      }
    },
    //重置
    Reset() {
      this.dataForm = {
        id: "",
        date: "6",
        createDates: "",
        createDatee: "",
        deptId: "", //部门
        userId: "",
        search: "",
        houseId: this.HousingID
      };
    },
    deptIdChange(val) {
      let a = "";
      if (this.$refs.myCascader.getCheckedNodes()[0]) {
        a = this.$refs.myCascader.getCheckedNodes()[0].value;
        this.dataForm.deptId = a;
        this.getUserList(a);
      } else {
        this.dataForm.deptId = "";
      }
    },
    // 获取部门员工列表
    getUserList(deptId) {
      let _this = this;
      this.$http
        .get(`/sys/user/deptUserList`, {
          params: {
            deptId: deptId
          }
        })
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          _this.maintainList = res.data;
        })
        .catch(() => {});
    }
  },
  watch: {
    dataForm: {
      handler(nowVal, oldVal) {
        this.getDataList();
      },
      deep: true
    },
    HousingID: {
      handler(newValue, oldValue) {
        this.dataForm.houseId = newValue;
        this.query();
      }
    }
  }
};
</script>
